﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using eCompany.eObj;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Windows;

namespace eCompany
{
    public static class eDataProxy
    {
        public static eData data { get; set; }


        public static void Initialize()
        {
            data = new eData();
        }
    }

    public class eData : INotifyPropertyChanged
    {
        private const string currentOrgFilename = @".\..\..\xml\company2.xml";
        public eCompany.eObj.organisation currentOrganisation;

        private Guid _currentCompany;
        public Guid currentCompany
        {
            get
            {
                return _currentCompany;
            }
            set
            {
                _currentCompany = value;
                RaisePropertyChanged("GetListOfItems");
            }
        }

        public ObservableCollection<account> GetListOfItems
        {
            get
            {
                eCompany.eObj.company cmp = currentOrganisation.getCompany(_currentCompany);
                return cmp.accountList;
            }
        }

        public eData()
        {
            currentOrganisation = eCompany.eObj.organisation.loadOrganisation(currentOrgFilename);
            RaisePropertyChanged("GetListOfItems");
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

    }
}
